package com.ostrich.cloud.common.result;



import com.ostrich.cloud.common.resultcode.CommonResultCode;
import com.ostrich.cloud.common.resultcode.ResultCode;

import java.io.Serializable;


public class Result implements Serializable {
	
	/*
	 * 响应编码
	 */
	private Integer code;
	
	/*
	 * 响应消息
	 */
	private String msg;
	
	/*
	 * 响应数据
	 */
	private Object data;


	public Result() {
	}

	public Result(int code, String msg, Object data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	public int getCode() {
		return code;
	}

	public Result setCode(int code) {
		this.code = code;
		return this;
	}

	public String getMsg() {
		return msg;
	}

	public Result setMsg(String msg) {
		this.msg = msg;
		return this;
	}

	public Object getData() {
		return data;
	}

	public static Result getInstance(ResultCode resultCode){
		Result result = new Result();
		result.setCode(resultCode.getCode());
		result.setMsg(resultCode.getMessage());
		return result;
	}

	public Result setData(Object data) {
		this.data = data;
		return this;
	}
	public static Result ok(){
		Result result = new Result();
		result.setCode(200);
		result.setMsg("请求成功");
		return result;
	}
	public static Result ok(Object data) {
		Result result = new Result();
		result.setCode(200);
		result.setMsg("请求成功");
		result.setData(data);
		return result;
	}
	public static Result okm(String msg) {
		Result result = new Result();
		result.setCode(200);
		result.setMsg(msg);
		return result;
	}
	public static Result ok(String msg,Object data) {
		Result result = new Result();
		result.setCode(200);
		result.setMsg(msg);
		result.setData(data);
		return result;
	}

	public static Result error() {
		Result result = new Result();
		result.setCode(500);
		result.setMsg("请求失败");
		return result;
	}

	public static Result error(int code,String msg) {
		Result result = new Result();
		result.setCode(code);
		result.setMsg(msg);
		return result;
	}
}
